﻿namespace UnityEditorInternal
{
    using NUnit.Framework;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using UnityEditor;
    using UnityEngine;

    public sealed class StateMachine : UnityEngine.Object
    {
        public StateMachine()
        {
            Internal_Create(this);
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern UnityEditorInternal.State AddState(string stateName);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern StateMachine AddStateMachine(string stateMachineName, StateMachine rootStateMachine);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern Transition AddTransition(UnityEditorInternal.State src, UnityEditorInternal.State dst);
        public UnityEditorInternal.State CreateStateWithMotion(Vector3 position, Motion motion)
        {
            Undo.RegisterUndo(this, "State added");
            string stateName = (motion == null) ? "New State" : motion.name;
            UnityEditorInternal.State state = this.AddState(stateName);
            state.SetPosition(position);
            state.SetMotion(0, motion);
            return state;
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern UnityEditorInternal.State DefaultState();
        public UnityEditorInternal.State FindState(int stateUniqueNameHash)
        {
            <FindState>c__AnonStorey16 storey = new <FindState>c__AnonStorey16 {
                stateUniqueNameHash = stateUniqueNameHash
            };
            return this.statesRecursive.Find(new Predicate<UnityEditorInternal.State>(storey.<>m__23));
        }

        public UnityEditorInternal.State FindState(string stateUniqueName)
        {
            <FindState>c__AnonStorey15 storey = new <FindState>c__AnonStorey15 {
                stateUniqueName = stateUniqueName
            };
            return this.statesRecursive.Find(new Predicate<UnityEditorInternal.State>(storey.<>m__22));
        }

        public Transition FindTransition(int transitionUniqueName)
        {
            <FindTransition>c__AnonStorey18 storey = new <FindTransition>c__AnonStorey18 {
                transitionUniqueName = transitionUniqueName
            };
            return this.transitions.Find(new Predicate<Transition>(storey.<>m__25));
        }

        public Transition FindTransition(string transitionUniqueName)
        {
            <FindTransition>c__AnonStorey17 storey = new <FindTransition>c__AnonStorey17 {
                transitionUniqueName = transitionUniqueName
            };
            return this.transitions.Find(new Predicate<Transition>(storey.<>m__24));
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern int GetMotionSetCount();
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern string GetName();
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern UnityEditorInternal.State GetState(int index);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern int GetStateCount();
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern StateMachine GetStateMachine(int index);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern int GetStateMachineCount();
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern Vector3 GetStateMachinePosition(int i);
        public Vector3 GetStateMachinePosition(StateMachine stateMachine)
        {
            for (int i = 0; i < this.GetStateMachineCount(); i++)
            {
                if (stateMachine == this.GetStateMachine(i))
                {
                    return this.GetStateMachinePosition(i);
                }
            }
            Assert.Fail("Can't find state machine (" + stateMachine.GetName() + ") in parent state machine (" + this.GetName() + ").");
            return Vector3.zero;
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern Transition[] GetTransitionsFromState(UnityEditorInternal.State srcState);
        public bool HasState(UnityEditorInternal.State state)
        {
            <HasState>c__AnonStorey19 storey = new <HasState>c__AnonStorey19 {
                state = state
            };
            return Enumerable.Any<UnityEditorInternal.State>(this.statesRecursive, new Func<UnityEditorInternal.State, bool>(storey.<>m__26));
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern bool HasState(UnityEditorInternal.State state, bool recursive);
        public bool HasStateMachine(StateMachine child)
        {
            <HasStateMachine>c__AnonStorey1B storeyb = new <HasStateMachine>c__AnonStorey1B {
                child = child
            };
            return Enumerable.Any<StateMachine>(this.stateMachinesRecursive, new Func<StateMachine, bool>(storeyb.<>m__28));
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern bool HasStateMachine(StateMachine state, bool recursive);
        public bool HasTransition(UnityEditorInternal.State stateA, UnityEditorInternal.State stateB)
        {
            <HasTransition>c__AnonStorey1C storeyc = new <HasTransition>c__AnonStorey1C {
                stateB = stateB,
                stateA = stateA
            };
            return (Enumerable.Any<Transition>(this.GetTransitionsFromState(storeyc.stateA), new Func<Transition, bool>(storeyc.<>m__29)) || Enumerable.Any<Transition>(this.GetTransitionsFromState(storeyc.stateB), new Func<Transition, bool>(storeyc.<>m__2A)));
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        private static extern void INTERNAL_CALL_SetStateMachinePosition(StateMachine self, int i, ref Vector3 pos);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        private static extern void Internal_Create(StateMachine mono);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        private extern void INTERNAL_get_anyStatePosition(out Vector3 value);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        private extern void INTERNAL_get_parentStateMachinePosition(out Vector3 value);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        private extern void INTERNAL_set_anyStatePosition(ref Vector3 value);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        private extern void INTERNAL_set_parentStateMachinePosition(ref Vector3 value);
        public bool IsDirectParent(StateMachine stateMachine)
        {
            <IsDirectParent>c__AnonStorey1A storeya = new <IsDirectParent>c__AnonStorey1A {
                stateMachine = stateMachine
            };
            return Enumerable.Any<StateMachine>(this.stateMachines, new Func<StateMachine, bool>(storeya.<>m__27));
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern string MakeUniqueStateMachineName(string newName);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern string MakeUniqueStateName(string newName);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern void RemoveState(UnityEditorInternal.State state);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern void RemoveStateMachine(StateMachine stateMachine);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern void RemoveTransition(Transition transition);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern void SetDefaultState(UnityEditorInternal.State state);
        public void SetStateMachinePosition(int i, Vector3 pos)
        {
            INTERNAL_CALL_SetStateMachinePosition(this, i, ref pos);
        }

        public void SetStateMachinePosition(StateMachine stateMachine, Vector3 position)
        {
            for (int i = 0; i < this.GetStateMachineCount(); i++)
            {
                if (stateMachine == this.GetStateMachine(i))
                {
                    this.SetStateMachinePosition(i, position);
                    return;
                }
            }
            Assert.Fail("Can't find state machine (" + stateMachine.GetName() + ") in parent state machine (" + this.GetName() + ").");
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern void SetTransitionsFromState(UnityEditorInternal.State srcState, Transition[] transitions);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern void SyncLocalTransitionsFrom(StateMachine root);

        public Vector3 anyStatePosition
        {
            get
            {
                Vector3 vector;
                this.INTERNAL_get_anyStatePosition(out vector);
                return vector;
            }
            set
            {
                this.INTERNAL_set_anyStatePosition(ref value);
            }
        }

        public Vector3 parentStateMachinePosition
        {
            get
            {
                Vector3 vector;
                this.INTERNAL_get_parentStateMachinePosition(out vector);
                return vector;
            }
            set
            {
                this.INTERNAL_set_parentStateMachinePosition(ref value);
            }
        }

        public IEnumerable<StateMachine> stateMachines
        {
            get
            {
                StateMachine[] machineArray = new StateMachine[this.GetStateMachineCount()];
                for (int i = 0; i < this.GetStateMachineCount(); i++)
                {
                    machineArray[i] = this.GetStateMachine(i);
                }
                return machineArray;
            }
        }

        public List<StateMachine> stateMachinesRecursive
        {
            get
            {
                List<StateMachine> list = new List<StateMachine>();
                list.AddRange(this.stateMachines);
                for (int i = 0; i < this.GetStateMachineCount(); i++)
                {
                    list.AddRange(this.GetStateMachine(i).stateMachinesRecursive);
                }
                return list;
            }
        }

        public IEnumerable<UnityEditorInternal.State> states
        {
            get
            {
                UnityEditorInternal.State[] stateArray = new UnityEditorInternal.State[this.GetStateCount()];
                for (int i = 0; i < this.GetStateCount(); i++)
                {
                    stateArray[i] = this.GetState(i);
                }
                return stateArray;
            }
        }

        public List<UnityEditorInternal.State> statesRecursive
        {
            get
            {
                List<UnityEditorInternal.State> list = new List<UnityEditorInternal.State>();
                list.AddRange(this.states);
                for (int i = 0; i < this.GetStateMachineCount(); i++)
                {
                    list.AddRange(this.GetStateMachine(i).statesRecursive);
                }
                return list;
            }
        }

        public int transitionCount { [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall] get; }

        public List<Transition> transitions
        {
            get
            {
                List<UnityEditorInternal.State> statesRecursive = this.statesRecursive;
                List<Transition> list2 = new List<Transition>();
                foreach (UnityEditorInternal.State state in statesRecursive)
                {
                    list2.AddRange(this.GetTransitionsFromState(state));
                }
                list2.AddRange(this.GetTransitionsFromState(null));
                return list2;
            }
        }

        [CompilerGenerated]
        private sealed class <FindState>c__AnonStorey15
        {
            internal string stateUniqueName;

            internal bool <>m__22(UnityEditorInternal.State s)
            {
                return (s.GetUniqueName() == this.stateUniqueName);
            }
        }

        [CompilerGenerated]
        private sealed class <FindState>c__AnonStorey16
        {
            internal int stateUniqueNameHash;

            internal bool <>m__23(UnityEditorInternal.State s)
            {
                return (s.GetUniqueNameHash() == this.stateUniqueNameHash);
            }
        }

        [CompilerGenerated]
        private sealed class <FindTransition>c__AnonStorey17
        {
            internal string transitionUniqueName;

            internal bool <>m__24(Transition t)
            {
                return (t.GetUniqueName() == this.transitionUniqueName);
            }
        }

        [CompilerGenerated]
        private sealed class <FindTransition>c__AnonStorey18
        {
            internal int transitionUniqueName;

            internal bool <>m__25(Transition t)
            {
                return (t.GetUniqueNameHash() == this.transitionUniqueName);
            }
        }

        [CompilerGenerated]
        private sealed class <HasState>c__AnonStorey19
        {
            internal UnityEditorInternal.State state;

            internal bool <>m__26(UnityEditorInternal.State s)
            {
                return (s == this.state);
            }
        }

        [CompilerGenerated]
        private sealed class <HasStateMachine>c__AnonStorey1B
        {
            internal StateMachine child;

            internal bool <>m__28(StateMachine sm)
            {
                return (sm == this.child);
            }
        }

        [CompilerGenerated]
        private sealed class <HasTransition>c__AnonStorey1C
        {
            internal UnityEditorInternal.State stateA;
            internal UnityEditorInternal.State stateB;

            internal bool <>m__29(Transition t)
            {
                return (t.GetDstState() == this.stateB);
            }

            internal bool <>m__2A(Transition t)
            {
                return (t.GetDstState() == this.stateA);
            }
        }

        [CompilerGenerated]
        private sealed class <IsDirectParent>c__AnonStorey1A
        {
            internal StateMachine stateMachine;

            internal bool <>m__27(StateMachine sm)
            {
                return (sm == this.stateMachine);
            }
        }
    }
}

